package com.athui.service;

import com.athui.bean.metadata.ColumnMetaData;
import com.athui.bean.task.SameTask;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @description: TODO
 * @autor: zhangzhonghui
 * @create: 2024-08-19 20:23
 * @Version: 1.0
 */
public abstract class QueueExplorerService<IN,OUT> extends ExplorerServer<IN,OUT> {

    private List<IN> dataList;


    public QueueExplorerService(List<IN> dataList){
        this.dataList = dataList;
    }

    public QueueExplorerService(Stream<IN> stream){
        this.dataList =stream.collect(Collectors.toList());
    }

    @Override
    public void open(StreamExecutionEnvironment env) {}

    @Override
    public DataStream<IN> source(StreamExecutionEnvironment env) {
        return env.fromCollection(dataList);
    }

    @Override
    public Integer  getRowSizeLimit() {
        return dataList.size();
    }

    @Override
    public void sink(DataStream<Tuple2<ColumnMetaData, SameTask>> stream) {
        stream.print();
    }

    @Override
    public String getJobName() {
        return "queue-job";
    }

    @Override
    public void run() throws Exception {
        super.run();
    }
}
